<?php defined('BASEPATH') or exit('No direct script access allowed');

class Plugin_Page extends Plugin
{
	public function navigation(){
		
		$start = $this->attribute('start') ? $this->attribute('start') : 0;
		$end = $this->attribute('end') ? $this->attribute('end') : 10;
		$this->load->model('page/navigation_m');
		$data = $this->navigation_m->get_all($parent = 0, $level = 0 ,$start,$end);
		return $this->navigation_render($data);
	}
	
	function navigation_render($data, $tag = NULL){
		$html = "";
		$tag_open = $tag_close = "";
		if($tag){
			$tag_open = "<".$tag.">";
			$tag_close = "</".$tag.">";
			$html .= $tag_open;
		}
		foreach($data as $item){
			$link = $item->uri ? base_url($item->uri) : base_url('page/'.$item->slug);
			
			$class = $item->_class ? "".$item->_class : "";
			$html .="<li class=\"page ".$class."\" page-rel=\"".$item->id."\">";
			$html .="<a href=\"$link\" title=\"".$item->title."\"><i></i>".$item->title."</a>";
			if($item->child)
				$html .= $this->navigation_render($item->child, "ul" );
			$html .="</li>";
		}
		return $html.$tag_close;
	}
}
